//
//  CSNavBarView.m
//  CarSalesMS_GCX
//
//  Created by Ssky on 2016/10/28.
//  Copyright © 2016年 Tony. All rights reserved.
//

#import "CSNavBarView.h"
#import "CSGXBackButton.h"
#import "CSBaseButton.h"

#define kMargin 10

@interface CSNavBarView ()

@property (nonatomic, strong) UIButton * selectedButton;

//@property (nonatomic, strong) NSArray<CSBaseButton *> *navButtons;

@end


@implementation CSNavBarView



#pragma mark - Actions
- (void)nav_btnClick:(CSBaseButton *)sender {
    NSLog(@"nav_btnClick");
    
    if ([self.navViewDelegate respondsToSelector:@selector(navBarView:backSelectedNavButtonType:)]) { }
    [self.navViewDelegate navBarView:self backSelectedNavButtonType:sender.tag];
    
}



#pragma markl - setupUI
-(void) setupUI {
    //
    self.backgroundColor = kColorBar;
    
    NSMutableArray<UIButton *> *navButtons = [NSMutableArray array];
    
    // backButton
    CSGXBackButton * backButton = [CSGXBackButton gx_textButton:@"车销出库" fontSize:16 normalColor:[UIColor whiteColor] selectedColor:nil];
    [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [self addSubview:backButton];
    backButton.tag = btnTypeBack;
    [navButtons addObject:backButton];
    
    [backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.top.leading.bottom.equalTo(self);
    }];
    
    // commit
    CSBaseButton * btnCommit = [CSBaseButton gx_textButton:@"提交" fontSize:16 normalColor:kColorWhite selectedColor:nil];
    [self addSubview:btnCommit];
    btnCommit.tag = btnTypeCommit;
    [navButtons addObject:btnCommit];
    
    [btnCommit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).offset(-kMargin);
        make.top.bottom.equalTo(self);
    }];
    
    // scan
    CSBaseButton * btnScan = [CSBaseButton gx_textButton:@"扫描" fontSize:16 normalColor:kColorWhite selectedColor:nil];
    [self addSubview:btnScan];
    btnScan.tag = btnTypeScan;
    [navButtons addObject:btnScan];
    
    [btnScan mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.right.equalTo(btnCommit.mas_left).offset(-kMargin);
    }];
    
    // search
    CSBaseButton * btnSearch = [CSBaseButton gx_textButton:@"搜索" fontSize:16 normalColor:kColorWhite selectedColor:nil];
    [self addSubview:btnSearch];
    btnSearch.tag = btnTypeSearch;
    [navButtons addObject:btnSearch];
    
    [btnSearch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.right.equalTo(btnScan.mas_left).offset(-kMargin);
    }];
    
    // refresh
    CSBaseButton * btnRefresh = [CSBaseButton gx_textButton:@"刷新" fontSize:16 normalColor:kColorWhite selectedColor:nil];
    [self addSubview:btnRefresh];
    btnRefresh.tag = btnTypeRefresh;
    [navButtons addObject:btnRefresh];
    
    [btnRefresh mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.right.equalTo(btnSearch.mas_left).offset(-kMargin);
    }];
    
    //    self.navButtons = navButtons.copy;
    
    for (UIButton *btn in navButtons) {
        [btn addTarget:self action:@selector(nav_btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    
}















#pragma mark - lazy
- (NSArray *)dataArr {
    if (!_dataArr) {
        _dataArr = [NSArray array];
    }
    return _dataArr;
}


@end
